/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.game.map;

import deatax.RNG;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author pson
 */
public class Map {

    /**
     * The number of x-coords the map has
     */
    private int width;
    /**
     * The number of y-coords the map has
     */
    private int height;
    private Tile[][] tiles;
    private List<Tile> list;

    public Map() {
    }

    public int getHeight() {
        return height;
    }

    public int getWidth() {
        return width;
    }

    /**
     * This clears the tiles to a size of w x h with all values set to null
     * @param w
     * @param h 
     */
    public void clearMap(int w, int h) {
        this.width = w;
        this.height = h;
        tiles = new Tile[w][h];
        list = new LinkedList<Tile>();
    }

    public Tile getTile(int x, int y) {
        return tiles[x][y];
    }

    public void setTile(Tile t) {
        tiles[t.getX()][t.getY()] = t;
        if (!list.contains(t)) {
            list.add(t);
        }
    }
    
    public Tile getRandomTile() {
        int n = RNG.rand(list.size());
        
        return list.get(n);
    }
}
